package com.example.administrator.shzs.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.administrator.shzs.R;
import com.example.administrator.shzs.db.GoodsBean;

import java.util.List;

/**
 * 订单页面的商品列表
 */
public class GoodsOrderAdapter extends RecyclerView.Adapter<GoodsOrderAdapter.MyViewHolder> {

    private Context context;

    private List<GoodsBean> mGoodsBeens;

    public GoodsOrderAdapter(Context context, List<GoodsBean> mGoodsBeens) {
        this.context = context;
        this.mGoodsBeens = mGoodsBeens;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view=View.inflate(context, R.layout.goods_listing_old_item,null);

        MyViewHolder holder=new MyViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {


        int num=Integer.parseInt(mGoodsBeens.get(position).getGoodsNum());
        double price=Double.parseDouble(mGoodsBeens.get(position).getGoodsPrice());
        double totalPrice=num*price;//总价

        holder.tvGoodsName.setText(mGoodsBeens.get(position).getGoodsName());
        holder.tvGoodsNum.setText("x"+num);
        holder.tvGoodsPrice.setText("￥"+totalPrice);


    }

    @Override
    public int getItemCount() {
        return mGoodsBeens==null ? 0 : mGoodsBeens.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{

        TextView tvGoodsName;
        TextView tvGoodsNum;
        TextView tvGoodsPrice;


        public MyViewHolder(View itemView) {
            super(itemView);

            tvGoodsName= (TextView) itemView.findViewById(R.id.tv_goods_name_old_item);
            tvGoodsNum= (TextView) itemView.findViewById(R.id.tv_goods_num_old_item);
            tvGoodsPrice= (TextView) itemView.findViewById(R.id.tv_goods_price_old_item);
        }
    }
}
